﻿/// <summary>
/// Thanks, ThoaiNguyen bro for this ideas
/// http://nthoai.blogspot.com/
/// </summary>

using System.Text;
using System.Web;

namespace NMA.Web.Core.Helper
{
    public enum NavigationTab
    {
        Category,
        News,
        Poll
    }

    public static class NavigationHelper
    {
        private static string RootPath;

        static NavigationHelper()
        {
            try
            {
                RootPath = VirtualPathUtility.ToAbsolute("~/");
            }
            catch
            {
                RootPath = string.Empty;
            }
        }

        public static string RenderNavigationBar(NavigationTab tab)
        {
            StringBuilder navagationHtml = new StringBuilder();

            navagationHtml.Append("<ul>");
            CreateTabHome(tab, navagationHtml);
            CreateTabFormSearch(tab, navagationHtml);
            CreateTabPrintQueue(tab, navagationHtml);
            navagationHtml.Append("</ul>");

            return navagationHtml.ToString();
        }

        private static void CreateTabHome(NavigationTab tab, StringBuilder navagationHtml)
        {
            if (tab.Equals(NavigationTab.Category))
            {
                navagationHtml.Append(string.Format("<li id=\"category\"><a href=\"{0}Admin\\Category\\Index\" class=\"current\"><span>{1}</span></a></li>", RootPath, "Category"));
            }
            else
            {
                navagationHtml.Append(string.Format("<li id=\"category\"><a href=\"{0}Admin\\Category\\Index\"><span>{1}</span></a></li>", RootPath, "Category"));
            }
        }

        private static void CreateTabFormSearch(NavigationTab tab, StringBuilder navagationHtml)
        {
            if (tab.Equals(NavigationTab.News))
            {
                navagationHtml.Append(string.Format("<li id=\"news\"><a href=\"{0}Admin\\News\\Index\" class=\"current\"><span>{1}</span></a></li>", RootPath, "News"));
            }
            else
            {
                navagationHtml.Append(string.Format("<li id=\"news\"><a href=\"{0}Admin\\News\\Index\"><span>{1}</span></a></li>", RootPath, "News"));
            }            
        }

        private static void CreateTabPrintQueue(NavigationTab tab, StringBuilder navagationHtml)
        {
            if (tab.Equals(NavigationTab.Poll))
            {
                navagationHtml.Append(string.Format("<li id=\"poll\"><a href=\"{0}Admin\\Poll\\Index\" class=\"current\"><span>{1}</span></a></li>", RootPath, "Poll"));
            }
            else
            {
                navagationHtml.Append(string.Format("<li id=\"poll\"><a href=\"{0}Admin\\Poll\\Index\"><span>{1}</span></a></li>", RootPath, "Poll"));
            }
        }
    }
}